package com.wall.haven.controller;

import com.wall.haven.service.ProxyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URISyntaxException;

@Controller
@RequestMapping("/proxy")
public class ProxyController {

    @Autowired
    private ProxyService proxyService;


    @RequestMapping("/image")
    public void proxy(@RequestParam String i, HttpServletResponse response) throws URISyntaxException, IOException {
        proxyService.proxyImage(i, response);
    }

    @ResponseBody
    @RequestMapping("api/**")
    public ResponseEntity<Object> proxy(HttpServletRequest request) {
        return proxyService.proxyApi(request);
    }
}
